

<!DOCTYPE html>

<html>

<head>
    <meta charset="UTF-8">
    <title>图片上传预览</title>
    <script type="text/javascript">

        function ProcessFile() {

            //获得文件对象
            var file = document.getElementById('file').files[0];
            return file.name;
            if (file) {

                var reader = new FileReader();

                reader.onload = function (event) {

                    var img = document.createElement("img");
                    img.height = 390;
                    img.width = 650;
                    //图片路径设置为读取的图片
                    //img.src = event.target.result;
                    img.src="http://192.168.31.116/"+file.name;
                    //在浏览器中显示图片
                    document.getElementById("result").appendChild(img);

                };

            }

            reader.readAsDataURL(file);
        }

        function contentLoaded() {
            document.getElementById('file').onsubmit;
            document.getElementById('file').addEventListener('change',

                ProcessFile, false);

        }

        window.addEventListener("DOMContentLoaded", contentLoaded, false);

    </script>

</head>

    <body>
        请选取一个图像文件: <input type="file" id="file" name="file"/>
    <div id="result">
    </div>

    </body>

</html>

